package cn.ffcs.unm.majorSkill.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.majorSkill.dao.MajorSkillDao;
import cn.ffcs.unm.majorSkill.model.BackboneTeam;
import cn.ffcs.unm.majorSkill.model.HighSkilledTalent;
import cn.ffcs.unm.majorSkill.model.ProQualification;
import cn.ffcs.unm.majorSkill.model.ProfessionalSkill;
import cn.ffcs.unm.majorSkill.model.ProfessionalTeam;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("majorSkillDao")
public class MajorSkillDaoImpl extends BaseDaoImpl implements MajorSkillDao {

	@Override
	public PageInfo queryInfoByProfessionalTeam(
			ProfessionalTeam professionalTeam, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_HI_PSNDOC_GLBDEF6 where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != professionalTeam) {
			if (!StrUtil.isEmpty(professionalTeam.getMonthId())) {
				sb.append(" and monthId = ? ");
				params.add(professionalTeam.getMonthId());
			}
			if (!StrUtil.isEmpty(professionalTeam.getPkPsndoc())) {
				sb.append(" AND pkpsndoc LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(professionalTeam
								.getPkPsndoc()) + "%");
			}
			if (!StrUtil.isEmpty(professionalTeam.getGlbdef1())) {
				sb.append(" AND glbdef1 LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(professionalTeam
								.getGlbdef1()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, ProfessionalTeam.class);
	}

	@Override
	public PageInfo queryInfoByBackboneTeam(BackboneTeam backboneTeam,
			int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select distinct ja1.PK_PSNDOC_SUB pkPsndocSub,ja3.code code, ");
		sb.append(" ja3.name name,ja1.MONTH_ID monthId,ja1.UNIT_ID unitId,ja1.RECORDNUM recordNum, ");
		sb.append(" ja1.ENDDATE endDate,ja1.GLBDEF1 glbdef1,ja1.GLBDEF2 glbdef2,ja1.GLBDEF3 glbdef3, ");
		sb.append(" ja1.GLBDEF4 glbdef4,ja1.GLBDEF5 glbdef5,ja1.GLBDEF6 glbdef6,ja1.LASTFLAG lastFlag, ");
		sb.append(" ja1.MODIFIEDTIME  modifiedTime,ja1.BEGINDATE beginDate,ja1.CREATIONTIME creationTime, ");
		sb.append(" ja1.TS ts,ja1.DR dr from LDAPM_MPW_HI_PSNDOC_GLBDEF8 ja1, LDAPM_MPW_bd_psndoc ja3 ");
		sb.append(" where JA1.pk_psndoc = JA3.pk_psndoc and ja1.month_id = ja3.month_id ");
		List<Object> params = new ArrayList<Object>();
		if (null != backboneTeam) {
			if (!StrUtil.isEmpty(backboneTeam.getMonthId())) {
				sb.append(" AND ja3.monthId = ? ");
				params.add(backboneTeam.getMonthId());
			}
			if (!StrUtil.isEmpty(backboneTeam.getName())) {
				sb.append(" AND ja3.NAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(backboneTeam.getName())
						+ "%");
			}
			if (!StrUtil.isEmpty(backboneTeam.getCode())) {
				sb.append(" AND ja3.CODE LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(backboneTeam.getCode())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, BackboneTeam.class);
	}

	@Override
	public PageInfo queryInfoByHighSkilledTalent(
			HighSkilledTalent highSkilledTalent, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append("select * from VIEW_HI_PSNDOC_GLBDEF7 where 1 = 1");
		
		List<Object> params = new ArrayList<Object>();
		if (null != highSkilledTalent) {
			if (!StrUtil.isEmpty(highSkilledTalent.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(highSkilledTalent.getMonthId());
			}
			if (!StrUtil.isEmpty(highSkilledTalent.getGlbdef1())) {
				sb.append(" AND glbdef1 LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(highSkilledTalent
								.getGlbdef1()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, HighSkilledTalent.class);
	}

	@Override
	public PageInfo queryInfoByProQualification(
			ProQualification proQualification, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder(" select * from VIEW_HI_PSNDOC_NATIONDUTY where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != proQualification) {
			if (!StrUtil.isEmpty(proQualification.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(proQualification.getMonthId());
			}
			if (!StrUtil.isEmpty(proQualification.getPkPsndoc())) {
				sb.append(" AND pkpsndoc LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(proQualification
								.getPkPsndoc()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, ProQualification.class);
	}

	@Override
	public PageInfo queryInfoByProfessionalSkill(
			ProfessionalSkill professionalSkill, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * from VIEW_HI_PSNDOC_TITLE where 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != professionalSkill) {
			if (!StrUtil.isEmpty(professionalSkill.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(professionalSkill
								.getMonthId());
			}
			if (!StrUtil.isEmpty(professionalSkill.getPkPsndoc())) {
				sb.append(" AND pkpsndoc LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(professionalSkill
								.getPkPsndoc()) + "%");
			}
			
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, ProfessionalSkill.class);
	}

}
